package com.kvw.filesystem.core;

import com.kt.kvw.generator.IDGenerator;

/**
 * Created with IntelliJ IDEA.
 * Desc:
 *
 * @author: keen
 * Date: 2020-08-01
 * Time: 21:20
 */
public abstract class AbstractStorage implements Storage {
    /**
     * 文件ID
     *
     * @return
     */
    protected String getFileId() {
        return IDGenerator.uuid();
    }

    /**
     * 文件名称
     *
     * @param fileId
     * @param fileName
     * @return
     */
    protected String getRealFileName(String fileId, String fileName) {
        String realFileName = fileName;
        if (fileName.startsWith(fileId)) {
            realFileName = realFileName.substring(0, fileId.length() + 1);
        }
        return realFileName;
    }

    protected String getUploadFileName(String fileId, String fileName) {
        int index = fileName.lastIndexOf(".");
        if (index > 0) {
            return fileId + fileName.substring(index);
        } else {
            return fileId;
        }
    }

}
